package hu.village.controller;

import hu.village.pojo.*;
import hu.village.service.CommitteeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class CommitteeController {

    @Autowired
    private CommitteeService committeeService;

    //委员绑定村庄
    @GetMapping("village/committee/binding")
    public Result bindingVillage(@RequestBody Village village){
        log.info("绑定村庄：{}",village);
        committeeService.bindingVillage(village);
        return Result.success("已提交绑定申请");
    }

    //提交账目信息
    @GetMapping("village/committee/add")
    public Result submitAccount(@RequestBody Account account){
        log.info("新增账目信息,{}",account);
        committeeService.submit(account);
        return Result.success("提交成功,等待审核");
    }

    //修改账目信息
    @GetMapping("village/committee/update")
    public Result updateAccount(@RequestBody Account account){
        log.info("修改信息,{}",account);
        committeeService.updateAccount(account);
        return Result.success("修改成功");
    }

    //查看历史账目
    @GetMapping("village/committee/selectHistoryAccount")
    public Result selectHistoryAccount(@RequestBody Account account,
                                       @RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "5") Integer pageSize){
        log.info("查询历史账目,{}",account);
        PageBean pageBean = committeeService.selectHistoryAccount(account,page,pageSize);
        return Result.success(pageBean);
    }

    //查看申请历史账目的申请
    @GetMapping("village/committee/selectApplication")
    public Result selectApplication(){
        List<User> userList= committeeService.selectApplication();
        return Result.success(userList);
    }

    //通过或驳回申请
    @GetMapping("village/committee/processApplication")
    public Result processApplication(Integer choice,Integer id){
        log.info("驳回或通过,{}",choice);
        committeeService.processApplication(choice,id);
        return Result.success("已处理");
    }
}
